import 'package:base_flutter/base_flutter.dart';
import 'package:fan_da_app/account/account_manager.dart';
import 'package:fan_da_app/account/user_manager.dart';

class NetConfigs{

  static NetConfigs? _instance;

  static NetConfigs get instance => _instance??=NetConfigs._();

  NetConfigs._();

  static String baseUrl = "http://192.168.31.215:8080/";

  void init(){
    HttpGo.HttpGogetInstance();
    HttpGo.instance.options = BaseOptions(
      contentType: Headers.jsonContentType
    );
    if(BuildConfig.isDebug){
      HttpGo.instance.setProxy("192.168.31.215", 8888, true);
    }
    HttpGo.instance.addInterceptor(TokenInterceptor());
  }
}

class TokenInterceptor extends InterceptorsWrapper{

  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    if(!AccountManager.instance.token.isNullOrEmpty()){
      options.headers["Authorization"] = AccountManager.instance.token;
    }
    super.onRequest(options, handler);
  }
}